<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('买房表列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>标题:</label>
                                <input type="text" name="title"/>
                            </li>
                            <li>
                                <label>图片地址:</label>
                                <input type="text" name="imgAddress"/>
                            </li>
                            <li>
                                <label>价格:</label>
                                <input type="text" name="price"/>
                            </li>
                            <li>
                                <label>房产类型:</label>
                                <input type="text" name="typehouseArea"/>
                            </li>
                            <li>
                                <label>优点标签:</label>
                                <input type="text" name="advantages"/>
                            </li>
                            <li>
                                <label>是否显示:</label>
                                <input type="text" name="ifNeedShow"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:buy:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:buy:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:buy:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:buy:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:residential:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:residential:remove')}]];
        var prefix = ctx + "system/residential";
        // 跳转的图片的地址
        var picAddr="";

        $(function() {

            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "编辑买房数据",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '编号',
                    visible: true
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'imgAddress',
                    title: '图片',
                    formatter: function(value, item, index) {
                            picAddr=value;
                            return '<img class="headImg" src="'+value+'" width="50px" height="50px"/>';

                    }
                },
                {
                    field: 'price',
                    title: '价格'
                },
                    {
                        field: 'area',
                        title: '面积(平方)'
                    },
                {
                    field: 'typehouseArea',
                    title: '房产类型'
                },
                {
                    field: 'advantages',
                    title: '优点标签',
                    //拼接出最后的优点标签字符串,发请求到数据库查询该编号对应什么标签名字
                    //再进行拼接
                    formatter: function(value, item, index) {
                        value="["+value+"]";
                        value=JSON.parse(value);
                        var tag;//把json字符串变成数组
                        var resString="";
                        $.ajax({
                            async :false,
                            type:"post",
                            url: "/system/advantage/listall",
                            success:function (res) {
                                tag=res;
                                for (var i=0;i<tag.length;i++){
                                    for (var j=0;j<value.length;j++) {
                                        if (tag[i].advantageId==value[j]) {
                                            resString+=tag[i].advantageName;
                                        }
                                    }
                                    resString+=" "
                                }



                            }
                        })
                        return resString;




                    }
                },
                {
                    field: 'ifNeedShow',
                    title: '是否显示',
                    formatter: function(value, item, index) {
                        if (value==1){
                            return "是";
                        }
                        if(value==0){
                            return "否"
                        }


                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        console.log()
                        var actions = [];
                        actions.push('<a class="btn btn-dark btn-xs ' + editFlag + '" href="'+prefix+'/edit_detail/'+row.id+'" ><i class="fa fa-edit"></i>内容详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);


        });
        window.onload = function(){
            //跳转到图片的新窗口
            $('.headImg').on('click', function () {
                window.open(picAddr);

            })
        }

    </script>

</body>
</html>